<template>
  <basic-container>
    <avue-crud
      :option="option"
      :table-loading="loading"
      :data="data"
      v-model="form"
      :defaults.sync="defaults"
      :page.sync="page"
      :permission="permissionList"
      :before-open="beforeOpen"
      ref="crud"
      @row-update="rowUpdate"
      @row-del="rowDel"
      @search-change="searchChange"
      @search-reset="searchReset"
      @selection-change="selectionChange"
      @current-change="currentChange"
      @size-change="sizeChange"
      @refresh-change="refreshChange"
      @on-load="onLoad"
    >
      <template slot="menuLeft">
        <el-button type="primary" size="small" icon="el-icon-plus" v-if="permission.feederManage_add" @click="addBtn">新 增</el-button>
        <!-- <el-button type="primary" size="small" icon="el-icon-check" v-if="permission.feederManage_inspection" @click="handleInpection">维 保</el-button> -->
        <el-button type="danger" size="small" icon="el-icon-delete" plain v-if="permission.feederManage_delete" @click="handleDelete">删 除 </el-button>
        <el-button type="warning" size="small" plain icon="el-icon-download" v-if="permission.feederManage_export" @click="$refs.exportComp.visible = true">导 出 </el-button>
      </template>
      <!--      <template slot="menuRight">-->
      <!--        <user-table-config :option="option" @confirm="(val) => handleSetUserConfig(val, pageCode)"></user-table-config>-->
      <!--      </template>-->
      <template slot-scope="{ row, index }" slot="menu">
        <el-button icon="el-icon-view" size="small" type="text" v-if="permission.feederManage_view" @click="rowView(row)">详情</el-button>
        <el-button icon="el-icon-edit" size="small" type="text" v-if="permission.feederManage_edit" @click="rowUpdate(row)">编辑</el-button>
        <!-- <el-button size="small" type="text" v-if="permission.feederManage_resume" @click="handleUsedDetail(row)">工具履历</el-button> -->
        <!-- <el-button
          v-if="permission.feederManage_enableOrDisable && row.status == 6"
          :disabled="Number(row.timesUsed) > Number(row.maxUsage) || !(row.status == 6)"
          icon="el-icon-circle-check"
          size="small"
          type="text"
          @click.stop="handleEnableOrDisable(row, 'enable')"
          v-preventReClick
          >启用
        </el-button>
        <el-button
          v-if="permission.feederManage_enableOrDisable && (row.status == 1 || row.status == 5)"
          :disabled="!(row.status == 1 || row.status == 5)"
          icon="el-icon-circle-close"
          size="small"
          type="text"
          @click.stop="handleEnableOrDisable(row, 'disable')"
          v-preventReClick
          >禁用
        </el-button> -->
      </template>
      <!-- <template slot="timesUsed" slot-scope="{ row }">
        <span style="color: #red" v-if="Number(row.timesUsed) > Number(row.maxUsage)">{{ row.timesUsed }}</span>
        <span v-else>{{ row.timesUsed }}</span>
      </template> -->
    </avue-crud>
    <!-- 新增 详情-->
    <el-dialog v-dragDirectives ref="dialog" :title="dialogTitle" append-to-body :visible.sync="showDialog" :close-on-click-modal="false" top="5vh" @close="closeDialog">
      <div class="sail-header-dialog-content">
        <avue-form ref="feederProperties" v-if="showDialog" v-model="form" :option="dialogOption">
          <template slot="PICTURE">
            <div v-if="dialogTitle != '详情' && form.PICTURE">
              <el-upload
                class="upload-demo"
                action="/api/blade-resource/oss/endpoint/put-file-attach"
                list-type="picture"
                accept="image/png, image/jpeg, image/jpg"
                :on-change="changeFile"
                :headers="headersObj"
                :on-preview="handlePreview"
                :before-upload="pictureUploadBefore"
                :on-success="pictureUploadSuccess"
                :file-list="pictureList"
              >
                <el-button size="small" type="primary">点击上传</el-button>
                <div slot="tip" class="el-upload__tip">只能上传png/jpeg/jpg文件</div>
              </el-upload>
            </div>
            <div v-if="dialogTitle === '详情' && JSON.stringify(form.PICTURE) != '[]'">
              <el-image style="width: 100px; height: 100px; padding-right: 10px; display: block" :src="form.PICTURE" @click="openPreview(0, form.PICTURE)"></el-image>
              <el-button type="text" icon="el-icon-download" size="small" @click="handleDownload(form.PICTURE)">下载</el-button>
            </div>
          </template>
          <template slot="INSPECTION">
            <div v-if="dialogTitle != '详情' && form.INSPECTION">
              <el-upload
                class="upload-demo"
                action="/api/blade-resource/oss/endpoint/put-file-attach"
                list-type="text"
                accept=".doc,.docx,.pdf"
                :on-change="changeFile"
                :headers="headersObj"
                :before-upload="textUploadBefore"
                :on-success="inspectionUploadSuccess"
                :file-list="inspectionList"
              >
                <el-button size="small" type="primary">点击上传</el-button>
                <div slot="tip" class="el-upload__tip">只能上传doc/docx/pdf文件</div>
              </el-upload>
            </div>
            <div v-if="dialogTitle === '详情' && JSON.stringify(form.INSPECTION) != '[]'">
              <div>{{ form.INSPECTIONNAME }}</div>
              <el-button type="text" icon="el-icon-download" size="small" @click="handleDownload(form.INSPECTION)">下载</el-button>
            </div>
          </template>
          <template slot="CERT">
            <div v-if="dialogTitle != '详情' && form.CERT">
              <el-upload
                class="upload-demo"
                action="/api/blade-resource/oss/endpoint/put-file-attach"
                list-type="text"
                accept=".doc,.docx,.pdf"
                :on-change="changeFile"
                :headers="headersObj"
                :before-upload="textUploadBefore"
                :on-success="certUploadSuccess"
                :file-list="certList"
              >
                <el-button size="small" type="primary">点击上传</el-button>
                <div slot="tip" class="el-upload__tip">只能上传doc/docx/pdf文件</div>
              </el-upload>
            </div>
            <div v-if="dialogTitle === '详情' && JSON.stringify(form.CERT) != '[]'">
              <div>{{ form.CERTNAME }}</div>
              <el-button type="text" icon="el-icon-download" size="small" @click="handleDownload(form.CERT)">下载</el-button>
            </div>
          </template>
        </avue-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button v-if="dialogTitle === '新增'" type="primary" size="small" @click="submit" v-preventReClick>
          <i class="el-icon-circle-plus-outline"></i><span>保 存</span>
        </el-button>
        <el-button v-if="dialogTitle === '编辑'" type="primary" size="small" @click="submit" v-preventReClick>
          <i class="el-icon-circle-check"></i><span>修 改</span>
        </el-button>
        <el-button size="small" @click="showDialog = false"><i class="el-icon-circle-close"></i><span>取 消</span></el-button>
      </span>
    </el-dialog>
    <!-- <el-dialog v-dragDirectives class="used-detail" ref="dialog" title="工具履历" append-to-body :visible.sync="detailDialog" :close-on-click-modal="false" top="5vh">
      <el-tabs type="border-card" v-if="detailDialog" v-model="tabsIndex" @tab-click="handleTabClick">
        <el-tab-pane label="使用记录" name="1"> </el-tab-pane>
        <el-tab-pane label="检验记录" name="2"> </el-tab-pane>
        <avue-crud
          :key="timer"
          :option="detailOption"
          :page.sync="detailPage"
          :data="detailData"
          :table-loading="detailLoading"
          v-model="detailForm"
          ref="leftCrud"
          @current-change="currentDetailChange"
          @size-change="sizeDetailChange"
          @on-load="onDetailLoad"
        >
          <template slot-scope="{ row, index }" slot="menu">
            <el-button icon="el-icon-view" size="small" type="text" @click="handleInspectionDetail(row)">详情</el-button>
          </template>
        </avue-crud>
      </el-tabs>
    </el-dialog>
    <el-dialog v-dragDirectives ref="dialog" title="检验记录" append-to-body :visible.sync="inspectionDetailDialog" :close-on-click-modal="false" top="5vh">
      <avue-form ref="basicInfo" v-if="inspectionDetailDialog" v-model="inspectionDetailForm" :option="inspectionDetailOption">
        <template slot="picture">
          <div v-for="(item, index) of inspectionDetailForm.attachmentList || []" :key="index">
            <div v-if="item.attachmentType === 'PICTURE'">
              <el-image style="width: 100px; height: 100px; padding-right: 10px; display: block" :src="item.link" @click="openPreview(index, item.link)"></el-image>
              <el-button type="text" icon="el-icon-download" size="small" @click="handleDownload(item.link)">下载</el-button>
            </div>
          </div>
        </template>
        <template slot="attach">
          <div v-for="(item, index) of inspectionDetailForm.attachmentList || []" :key="index">
            <div v-if="item.attachmentType === 'INSPECTION'">
              <div>{{ item.originalName }}</div>
              <el-button type="text" icon="el-icon-download" size="small" @click="handleDownload(item.link)">下载</el-button>
            </div>
          </div>
        </template>
      </avue-form>
      <span slot="footer" class="dialog-footer">
        <el-button size="small" @click="inspectionDetailDialog = false"><i class="el-icon-circle-close"></i><span>取 消</span></el-button>
      </span>
    </el-dialog> -->
    <common-modal-template ref="commonModalTemplate" :option="tableOption" @getSelectedRows="getSelectedRows" @newKey="newKey"> </common-modal-template>
    <export-comp ref="exportComp" page-api-url="mes-product/ems-equipment/page" :option="option" :page="page" :query="query" file-name="飞达管理"> </export-comp>
  </basic-container>
</template>
<script>
import {
  getSteelMeshList,
  getProductList,
  inspectionDetail,
  getDetail,
  getUseRecord,
  getInspectionRecord,
  add,
  remove,
  enableOrDisable,
  inspection
} from '@/api/product/feederManage';
import { mapGetters } from 'vuex';
import CommonModalTemplate from '@/components/common-modal-template/common-modal-template.vue';
import website from '@/config/website';
import exportComp from '@/components/export-comp';
import { Base64 } from 'js-base64';
import { getToken } from '@/util/auth';
import userTableConfig from '@/components/user-table-config';
import userConfig from '@/mixins/userConfig';
import feederMixin from './mixins/feederMixin';
export default {
  name: 'FEEDER_MANAGE',
  components: {
    CommonModalTemplate,
    exportComp,
    userTableConfig
  },
  mixins: [userConfig(), feederMixin],
  data() {
    return {
      pageCode: 'FEEDER_MANAGE',
      transferDialog: false,
      inspectionDetailDialog: false,
      form: {},
      detailForm: {},
      inspectionDetailForm: {},
      defaults: {},
      query: {
        subType: 'FEEDER'
      },
      loading: true,
      leftLoading: true,
      detailLoading: false,
      tabsIndex: '1',
      detailDialog: false,
      page: {
        pageSize: 20,
        currentPage: 1,
        total: 0
      },
      detailPage: {
        pageSize: 20,
        currentPage: 1,
        total: 0
      },
      detailData: [],
      selectionList: [],
      dialogTitle: '新增',
      showDialog: false,
      timer: new Date().getTime(), //不同内容使用同一个模态框结构，key值不同需要重新请求渲染数据，否则会请求到上一个使用的数据内容
      modalName: '', //打开公用模态框名称
      tableOption: {}, //公用模态框配置信息
      data: [],
      pictureList: [],
      inspectionList: [],
      certList: []
    };
  },
  mounted() {
    this.$nextTick(() => {
      this.$structuralSplit();
    });
  },
  computed: {
    ...mapGetters(['permission']),
    permissionList() {
      return {
        addBtn: this.vaildData(this.permission.feederManage_add, false),
        viewBtn: this.vaildData(this.permission.feederManage_view, false),
        delBtn: this.vaildData(this.permission.feederManage_delete, false),
        editBtn: this.vaildData(this.permission.feederManage_edit, false)
      };
    },
    ids() {
      let ids = [];
      this.selectionList.forEach((ele) => {
        ids.push(ele.id);
      });
      return ids.join(',');
    },
    headersObj() {
      let header = { Authorization: `Basic ${Base64.encode(`${website.clientId}:${website.clientSecret}`)}` };
      header['Blade-Auth'] = 'bearer ' + getToken();
      return header;
    },
    isDisable() {
      return this.dialogTitle === '详情';
    }
  },
  methods: {
    handleInspectionDetail(row) {
      inspectionDetail(row.id).then((res) => {
        try {
          let data = res.data.data || {};
          let equipmentVO = data.equipmentVO || {};
          let optionsJson = typeof data.options === 'string' ? JSON.parse(data.options) : {};
          this.inspectionDetailForm = {
            ...data,
            ...optionsJson,
            equipmentCode: equipmentVO.code,
            equipmentName: equipmentVO.name,
            specification: equipmentVO.specification,
            areaName: equipmentVO.areaName,
            tensionWarn: equipmentVO.tensionWarn
          };
        } catch (error) {
          console.log(error);
        }
      });
      this.inspectionDetailDialog = true;
    },
    handleTabClick() {
      this.detailData = [];
      this.detailPage = {
        pageSize: 20,
        currentPage: 1,
        total: 0
      };
      var object = {
        1: 'usedRecordColumnFn',
        2: 'inspectionColumnFn'
      };
      this[object[this.tabsIndex]]();
    },
    usedRecordColumnFn() {
      this.detailOption.menu = false;
      this.detailOption.column = this.usedRecordColumn;
      this.onDetailLoad(this.detailPage);
    },
    inspectionColumnFn() {
      this.detailOption.menu = true;
      this.detailOption.column = this.inspectionColumn;
      this.onDetailLoad(this.detailPage);
    },
    handleUsedDetail(row) {
      this.detailPage = {
        pageSize: 20,
        currentPage: 1,
        total: 0
      };
      this.tabsIndex = '1';
      this.detailData = [];
      this.form = row;
      this.detailOption.column = this.usedRecordColumn;
      this.detailDialog = true;
    },
    handleInpection() {
      if (this.selectionList.length === 0) {
        this.$message({
          type: 'warning',
          message: '请选择一条数据!'
        });
        return;
      }
      this.$confirm('是否进行维保?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          return inspection(this.ids);
        })
        .then(() => {
          this.onLoad(this.page);
          this.$message({
            type: 'success',
            message: '操作成功!'
          });
          this.$refs.crud.toggleSelection();
        });
    },
    selectionLeftChange(list) {
      this.leftSelectionList = list;
    },
    currentDetailChange(currentPage) {
      this.detailPage.currentPage = currentPage;
      this.onDetailLoad(this.detailPage);
    },
    sizeDetailChange(pageSize) {
      this.detailPage.pageSize = pageSize;
      this.onDetailLoad(this.detailPage);
    },
    /**
     * 重新加载公用表格弹窗组件
     */
    newKey() {
      this.timer = new Date().getTime();
    },
    handleDelete() {
      if (this.selectionList.length === 0) {
        this.$message.warning('请选择至少一条数据');
        return;
      }
      this.$confirm('确定将选择数据删除?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          return remove(this.ids);
        })
        .then(() => {
          this.onLoad(this.page);
          this.$message({
            type: 'success',
            message: '操作成功!'
          });
          this.$refs.crud.toggleSelection();
        });
    },
    searchReset() {
      this.query = {
        type: 'TOOL',
        subType: 'FEEDER'
      };
      this.onLoad(this.page);
    },
    searchChange(params, done) {
      this.query = params;
      this.page.currentPage = 1;
      this.onLoad(this.page, params);
      done();
    },
    selectionChange(list) {
      this.selectionList = list;
    },
    selectionClear() {
      this.selectionList = [];
      this.$refs.crud.toggleSelection();
    },
    currentChange(currentPage) {
      this.page.currentPage = currentPage;
    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
    },
    refreshChange() {
      this.onLoad(this.page, this.query);
    },
    onLoad(page, params = {}) {
      this.loading = true;
      params.type = 'TOOL';
      params.subType = 'FEEDER';
      getSteelMeshList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then((res) => {
        const data = res.data.data;
        this.page.total = data.total || 0;
        this.data = data.records;
        this.loading = false;
        this._forEach(this.data, (item) => {
          item.status = String(item.status);
        });
        this.selectionClear();
      });
    },
    handleRightData(data, filters) {
      if (filters.length === 0) return;
      let rightData = [];
      this._forEach(data, (item) => {
        this._forEach(filters, (item2) => {
          if (item.id === item2.partMasterId) rightData.push(item);
        });
      });
      return rightData;
    },
    onLeftLoad(page, params = {}) {
      this.leftLoading = true;
      getProductList(page.currentPage, page.pageSize, Object.assign(params)).then((res) => {
        const data = res.data.data;
        this.leftPage.total = data.total;
        this.leftData = data.records;
        // this.rightData = this.handleRightData(this.leftData, this.form.equipmentPartList);
        this.leftLoading = false;
      });
    },
    onDetailLoad(page, params = {}) {
      this.detailLoading = true;
      if (this.tabsIndex === '1') {
        params.toolId = this.form.id;
        getUseRecord(page.currentPage, page.pageSize, Object.assign(params)).then((res) => {
          const data = res.data.data;
          this.detailPage.total = data.total;
          this.detailData = this._map(data.records, (item) => {
            let optionsJson = typeof item.options === 'string' ? JSON.parse(item.options) : {};
            return {
              ...optionsJson,
              ...item
            };
          });
          this.detailLoading = false;
        });
      } else {
        params.equipmentId = this.form.id;
        getInspectionRecord(page.currentPage, page.pageSize, Object.assign(params)).then((res) => {
          const data = res.data.data;
          this.detailPage.total = data.total;
          this.detailData = data.records;
          this.detailLoading = false;
        });
      }
    },
    addBtn() {
      this.form = {};
      this.showDialog = true;
      this.dialogOption.detail = false;
      this.dialogTitle = '新增';
    },
    restForm() {},
    handleEnableOrDisable(row, btnType) {
      if (btnType === 'enable') {
        if (Number(row.timesUsed) > Number(row.maxUsage)) {
          this.$message({
            type: 'warning',
            message: `已使用次数超出最大使用次数`
          });
          return;
        }
        this.$confirm('是否确定启用这条数据?', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          enableOrDisable({
            id: row.id,
            status: 1
          }).then(
            () => {
              this.onLoad(this.page);
              this.$message({
                type: 'success',
                message: '已启用!'
              });
            },
            (error) => {}
          );
        });
      } else {
        this.$confirm('是否确定禁用这条数据?', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          enableOrDisable({
            id: row.id,
            status: 6
          }).then(
            () => {
              this.onLoad(this.page);
              this.$message({
                type: 'success',
                message: '已禁用!'
              });
            },
            (error) => {}
          );
        });
      }
    },
    /**
     * 获取选择的模态框行数据
     */
    getSelectedRows(rowData) {
      switch (this.modalName) {
        case 'principalModal':
          this.$set(this.form, 'principal', this._get(rowData, 'id', ''));
          this.$set(this.form, 'principalName', this._get(rowData, 'realName', ''));
          break;
        case 'areaModal':
          if (rowData.areaType !== 'STORAGE') {
            this.$message({
              type: 'warning',
              message: '存储位置应选择对应储位，请选择对应储位'
            });
            return;
          }
          this.form.areaName = this._get(rowData, 'name', '');
          this.form.areaCode = this._get(rowData, 'code', '');
          this.form.areaId = this._get(rowData, 'id', '');
          break;
        case 'vendorModal':
          this.form.vendorId = this._get(rowData, 'id', '');
          this.form.vendorName = this._get(rowData, 'name', '');
          this.form.vendorCode = this._get(rowData, 'partnerNo', '');
          break;
        default:
          break;
      }
    },
    pictureUploadSuccess(res) {
      if (this.form.attachmentList) {
        for (let i = 0; i < this.form.attachmentList.length; i++) {
          if ('EQUIPMENT_PICTURE' === this.form.attachmentList[i].type) {
            this.form.attachmentList.splice(i, 1);
          }
        }
      } else {
        this.form.attachmentList = [];
      }
      this.form.PICTURE = res.data.link;
      this.form['attachmentList'].push({
        attachmentId: res.data.attachId,
        link: res.data.link,
        originalName: res.data.originalName,
        type: 'EQUIPMENT_PICTURE',
        attachmentName: res.data.originalName
      });
      console.log(this.pictureList, ' this.pictureList');
    },
    inspectionUploadSuccess(res) {
      if (this.form.attachmentList) {
        for (let i = 0; i < this.form.attachmentList.length; i++) {
          if ('ACCEPTANCE_REPORT' === this.form.attachmentList[i].type) {
            this.form.attachmentList.splice(i, 1);
          }
        }
      } else {
        this.form.attachmentList = [];
      }
      this.form.INSPECTION = res.data.link;
      this.form['attachmentList'].push({
        attachmentId: res.data.attachId,
        link: res.data.link,
        originalName: res.data.originalName,
        attachmentName: res.data.originalName,
        type: 'ACCEPTANCE_REPORT'
      });
    },
    certUploadSuccess(res) {
      if (this.form.attachmentList) {
        for (let i = 0; i < this.form.attachmentList.length; i++) {
          if ('PRODUCTION_VALIDATION' === this.form.attachmentList[i].type) {
            this.form.attachmentList.splice(i, 1);
          }
        }
      } else {
        this.form.attachmentList = [];
      }
      this.form.CERT = res.data.link;
      this.form['attachmentList'].push({
        attachmentId: res.data.attachId,
        link: res.data.link,
        originalName: res.data.originalName,
        attachmentName: res.data.originalName,
        type: 'PRODUCTION_VALIDATION'
      });
    },

    changeFile(files, fileList) {
      if (fileList.length > 1) {
        fileList.splice(0, 1);
      }
    },
    /**
     * 上传前方法
     */
    pictureUploadBefore(file) {
      console.log(file);
      if (file.name.split('.')[1] != 'png' && file.name.split('.')[1] != 'jpeg' && file.name.split('.')[1] != 'jpg') {
        this.$message({
          type: 'warning',
          message: '只能上传png/jpeg/jpg文件！'
        });
        return false;
      }
    },
    textUploadBefore(file) {
      if (file.name.split('.')[1] != 'doc' && file.name.split('.')[1] != 'docx' && file.name.split('.')[1] != 'pdf') {
        this.$message({
          type: 'warning',
          message: '只能上传dox/docx/pdf文件！'
        });
        return false;
      }
    },
    /**
     * 提交
     */
    async submit() {
      delete this.form.PICTURE;
      delete this.form.INSPECTION;
      delete this.form.CERT;
      this.form.type = 'TOOL';
      this.form.subType = 'FEEDER';
      this.form.attachmentList = this._cloneDeep(this.form.attachmentList);
      this.$refs.feederProperties.validate((valid, done) => {
        if (valid) {
          add(this.form).then((res) => {
            this.onLoad(this.page);
            this.$message({
              type: 'success',
              message: res.data.msg
            });
            this.showDialog = false;
          });
        }
        done();
      });
    },
    /**
     * 查看详情数据
     */
    rowView(row) {
      this.showDialog = true;
      this.dialogOption.detail = true;
      this.dialogTitle = '详情';
      getDetail(row.id).then((res) => {
        let data = res.data.data;
        this.handleDetailData(data);
      });
    },
    rowUpdate(row) {
      this.showDialog = true;
      this.dialogOption.detail = false;
      this.dialogTitle = '编辑';
      row.options = JSON.stringify({ version: row.version });
      getDetail(row.id).then((res) => {
        let data = res.data.data;
        this.handleDetailData(data);
      });
    },
    handleDetailData(data) {
      this.form = data;
      this._forEach(data.attachmentList, (item) => {
        if (item.type === 'EQUIPMENT_PICTURE') {
          item.url = item.link;
          this.form.PICTURE = item.link;
        } else if (item.type === 'ACCEPTANCE_REPORT') {
          this.form.INSPECTION = item.link;
          this.form.INSPECTIONNAME = item.attachmentName;
          item.name = item.attachmentName;
        } else if (item.type === 'PRODUCTION_VALIDATION') {
          this.form.CERT = item.link;
          this.form.CERTNAME = item.attachmentName;
          item.name = item.attachmentName;
        }
      });
      this.pictureList = this._filter(data.attachmentList || [], (item) => item.type === 'EQUIPMENT_PICTURE');
      this.inspectionList = this._filter(data.attachmentList || [], (item) => item.type === 'ACCEPTANCE_REPORT');
      this.certList = this._filter(data.attachmentList || [], (item) => item.type === 'PRODUCTION_VALIDATION');
    },
    rowDel(row) {
      this.$confirm('确定将选择数据删除?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          return remove([row.id]);
        })
        .then(() => {
          this.onLoad(this.page);
          this.$message({
            type: 'success',
            message: '操作成功!'
          });
        });
    },
    closeDialog() {
      this.form = {};
      this.pictureList = [];
      this.inspectionList = [];
      this.certList = [];
    },
    handleDownload(link) {
      window.open(`${link}`);
    },
    openPreview(index = 0, link) {
      this.$ImagePreview([{ url: link }], index, {
        closeOnClickModal: false
      });
    }
  }
};
</script>
<style lang="scss" scoped>
.tranfer-dialog {
  ::v-deep .avue-crud__search {
    width: 100% !important;
    border: none !important;
  }
  ::v-deep .avue-crud__right {
    display: none !important;
  }
}
.used-detail {
  ::v-deep .avue-crud__menu {
    display: none;
  }
}
</style>
